import { Injectable } from "@nestjs/common";
import { PassportStrategy } from "@nestjs/passport";
import { Strategy, ExtractJwt } from "passport-jwt";
import { jwtConstants } from "../constants/constants";

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
    constructor() {
        super({
            jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),//.fromHeader('token'),
            ignoreExpiration: false,
            secretOrKey: jwtConstants.secret,

        });
    }

    async validate(payload: any) {
        return { userId: payload.userId, username: payload.username, roles: payload.roles }
    }
}